#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
const int N = 2e5+10;
char op[N];
int xnums[N],xnc;
int ynums[N],ync;
int q1[N],q2[N],q3[N],q4[N];
inline int lowbit(int x){
    return x&(-x);
}
struct BLT1{
    int tre[N];
    void update(int p,int v){   
        for(int i = p;i <= max(xnc,ync);i += lowbit(i)){
            tre[i] += v;
        }
    }
    int query(int p){
        int res = 0;
        for(int i = p;i >= 1;i -= lowbit(i)){
            res += tre[i];
        }
        return res;
    }
}dl,dr,du,dd;
random_device seed;
mt19937 mt(seed());
struct BLT2{
    __gnu_pbds::tree<pair<int,unsigned int>,__gnu_pbds::null_type,less<pair<int,unsigned int>>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> tre[N];
    void insert(int p,int v){
        for(int i = p;i <= xnc;i += lowbit(i)){
            tre[i].insert(make_pair(v,mt()));
        }
    }
    void remove(int p,int v){
        for(int i = p;i <= xnc;i += lowbit(i)){
            auto p = tre[i].lower_bound(make_pair(v,0));
            tre[i].erase(p);
        }
    }
    int query(int p,int x,int y){
        int res = 0;
        for(int i = p;i >= 1;i -= lowbit(i)){
            res += tre[i].order_of_key(make_pair(y + 1,0)) - tre[i].order_of_key(make_pair(x,0));
        }
        return res;
    }
    int query(int l,int r,int x,int y){
        return query(r,x,y) - query(l - 1,x,y);
    }
}ld,lu,rd,ru;
struct rect{
    int x1,y1,x2,y2;
}recs[N];
int main(){
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>op[i];
        if(op[i] == 'D'){
            cin>>q1[i];
        }else{
            cin>>q1[i]>>q2[i]>>q3[i]>>q4[i];
            xnums[++xnc] = q1[i];
            xnums[++xnc] = q3[i];
            ynums[++ync] = q2[i];
            ynums[++ync] = q4[i];
        }
    }
    sort(xnums + 1,xnums + 1 + xnc);
    xnc = unique(xnums + 1,xnums + 1 + xnc) - xnums - 1;
    sort(ynums + 1,ynums + 1 + ync);
    ync = unique(ynums + 1,ynums + 1 + ync) - ynums - 1;
    int lcnt = 0,llcur = 0;
    for(int i = 1;i<=n;i++){
        if(op[i] == 'Q'){
            int x1 = lower_bound(xnums + 1,xnums + xnc + 1,q1[i]) - xnums;
            int y1 = lower_bound(ynums + 1,ynums + ync + 1,q2[i]) - ynums;
            int x2 = lower_bound(xnums + 1,xnums + xnc + 1,q3[i]) - xnums;
            int y2 = lower_bound(ynums + 1,ynums + ync + 1,q4[i]) - ynums;
            int exp = lcnt - dl.query(x2)
                    + dr.query(x1 - 1)
                    + lcnt - dd.query(y2)
                    + du.query(y1 - 1)
                    - ld.query(x2 + 1,xnc,y2 + 1,ync) 
                    - lu.query(x2 + 1,xnc,1,y1 - 1)
                    - rd.query(1,x1 - 1,y2 + 1,ync)
                    - ru.query(1,x1 - 1,1,y1 - 1);
            cout<<lcnt - exp<<'\n';
        }else if(op[i] == 'I'){
            int x1 = lower_bound(xnums + 1,xnums + xnc + 1,q1[i]) - xnums;
            int y1 = lower_bound(ynums + 1,ynums + ync + 1,q2[i]) - ynums;
            int x2 = lower_bound(xnums + 1,xnums + xnc + 1,q3[i]) - xnums;
            int y2 = lower_bound(ynums + 1,ynums + ync + 1,q4[i]) - ynums;
            recs[++llcur] = {x1,y1,x2,y2};
            dl.update(x1,1);
            dr.update(x2,1);
            du.update(y2,1);
            dd.update(y1,1);
            ld.insert(x1,y1);
            rd.insert(x2,y1);
            lu.insert(x1,y2);
            ru.insert(x2,y2);
            lcnt++;
        }else{
            int x = q1[i];
            int x1 = recs[x].x1,x2 = recs[x].x2,y1 = recs[x].y1,y2 = recs[x].y2;
            dl.update(x1,-1);
            dr.update(x2,-1);
            du.update(y2,-1);
            dd.update(y1,-1);
            ld.remove(x1,y1);
            rd.remove(x2,y1);
            lu.remove(x1,y2);
            ru.remove(x2,y2);
            lcnt--;
        }
    }
}